//
// OpenTemplate
// Copyright (c) 2006
// by OpenArrow Software ( http://www.openarrow.com )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;

namespace OpenArrow.Templating.Compilation
{
    /// <summary>
    /// Represents the results of the compilation of a template's source code into a .Net Assembly
    /// <see cref="OpenArrow.Templating.ActionResults"/>
    /// </summary>
    public class TemplateCompilerResults : ActionResults
    {
        private CompilerResults codeDomResults;

        /// <summary>
        /// Gets or sets the results from the CodeDOM Compiler that compiled the template source code
        /// </summary>
        public CompilerResults CodeDomResults
        {
            get { return codeDomResults; }
            set { codeDomResults = value; }
        }

        /// <summary>
        /// Constructs an empty <see cref="System.CodeDom.Compiler.CompilerResults"/> class
        /// </summary>
        public TemplateCompilerResults() : base() { }

        /// <summary>
        /// Constructs a new <see cref="TemplateCompilerResults"/> class representing a successful compilation with the specified
        /// output
        /// </summary>
        /// <param name="codeDomResults">The results from the CodeDOM Compiler that compiled the template source code</param>
        public TemplateCompilerResults(CompilerResults codeDomResults) : this(codeDomResults, new ProblemCollection()) { }

        /// <summary>
        /// Constructs a new <see cref="TemplateCompilerResults"/> class representing the results of compilation
        /// with the specified output and problems. The value of <see cref="ActionResults.Success"/> is determined
        /// by the <see cref="ProblemCollection.ErrorCount"/> property of <paramref name="problems"/>
        /// </summary>
        /// <param name="codeDomResults">The results from the CodeDOM Compiler that compiled the template source code</param>
        /// <param name="problems">The problems that occurred during the action</param>
        public TemplateCompilerResults(CompilerResults codeDomResults, ProblemCollection problems) : this(codeDomResults, 
            problems, problems.ErrorCount == 0) { }

        /// <summary>
        /// Constructs a new <see cref="TemplateCompilerResults"/> class representing the results of compilation
        /// with the specified output, problems and success.
        /// </summary>
        /// <param name="codeDomResults">The results from the CodeDOM Compiler that compiled the template source code</param>
        /// <param name="problems">The problems that occurred during the action</param>
        /// <param name="success">A boolean specifying if the action was successful</param>
        public TemplateCompilerResults(CompilerResults codeDomResults, ProblemCollection problems, bool success)
            : base(problems, success)
        {
            this.CodeDomResults = codeDomResults;
        }
    }
}
